package leecode

func pivoIndex(nums []int) int {
	//先计算切片中元素的总和
	var total int
	for _, value := range nums {
		total += value // 2
	}
	var sumLeft int //sumLeft表示左侧和
	for index, value := range nums {
		//总和减去左侧和等于右侧和
		if sumLeft+value == total-sumLeft {
			return index
		}
		sumLeft += value
	}
	return -1
}
